package com.uwo.house.service.serviceImpl;

import com.uwo.house.beans.request.*;
import com.uwo.house.beans.response.MessageManagerResp;
import com.uwo.house.dao.*;
import com.uwo.house.service.IProjectManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by PHS on 2017/7/19.
 */
@Service
public class ProjectManagerService implements IProjectManagerService {

    @Autowired
    private ProjectManagerDao projectManagerDao;

    @Autowired
    private ProjectManagerReplyDao projectManagerReplyDao;

    @Autowired
    private DesignOrderStatusDao designOrderStatusDao;

    @Autowired
    private DesignSchemeDao designSchemeDao;

    @Autowired
    private MeasureCenterDao measureCenterDao;

    @Autowired
    private MessageDao messageDao;

    public int addProjectInfo(ProjectManagerReq projectManagerReq) {
        return projectManagerDao.addProjectInfo(projectManagerReq);
    }

    @Transactional
    public int updateProjectStatus(String orderId) {
        int result = 0;
        int result1 = designOrderStatusDao.updateProjectStatus(orderId);
        int result2 = projectManagerDao.updateProjectInfoStatus(orderId);
        if (result1 > 0 && result2 > 0) {
            result = 1;
        }
        return result;
    }

    public List<ProjectManagerReq> projectDetail(String  constractNumber) {
        return projectManagerDao.projectDetail(constractNumber);
    }

    @Transactional
    public int addReplay(ProjectManagerReplyReq projectManagerReplyReq) {
        if (null != projectManagerReplyReq){
            Integer messageId = projectManagerReplyReq.getMessageId();
            int result1 = updateStatus(messageId);
            int result2 = projectManagerReplyDao.addReplay(projectManagerReplyReq);
            if (result1 > 0 && result2 > 0) {
                return 1;
            }
        }
        return 0;
    }

    public DesignSchemeReq findDesignScheme(String orderId, String userId) {
        return designSchemeDao.findDesignScheme(orderId,userId);
    }

    public List<DesignOrderStatusReq> findUserByOrderId(String orderId) {
        return designOrderStatusDao.findUserByOrderId(orderId);
    }

    public List<MessageManagerResp> getToProjectManager(String orderId, String mobile, Integer messageType, Integer handleStatus) {
        return measureCenterDao.getToProjectManager(orderId,mobile,messageType,handleStatus);
    }

    public MeasureCenterReq findMessageInfo(String orderId,Integer messageId) {
        return measureCenterDao.findMessageInfo(orderId,messageId);
    }

    public int updateStatus(Integer messageId) {
        return messageDao.updateStatus(messageId);
    }

    public MeasureCenterReq findMessageDetail(String orderId,Integer messageId) {
        return measureCenterDao.findMessageDetail(orderId,messageId);
    }

    public List<MeasureCenterReq> getToSupplier(String orderId, String mobile, Integer messageType, Integer handleStatus,String userId) {
        return measureCenterDao.getToSupplier(orderId,mobile,messageType,handleStatus,userId);
    }
}
